package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import biz.FoodBiz;
import biz.FoodTypeBiz;
import biz.NewsBiz;
import biz.RateBiz;
import biz.impl.FoodBizImpl;
import biz.impl.FoodTypeBizImpl;
import biz.impl.NewsBizImpl;
import biz.impl.RateBizImpl;
import entity.Food;
import entity.FoodType;
import entity.News;
import entity.Rate;


@WebServlet("/Index.html")
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		FoodBiz fb= new FoodBizImpl();
		List<Food> foodlist = fb.queryAllFood();
		
		FoodTypeBiz ftb = new FoodTypeBizImpl();
		FoodType pizzafoodType = ftb.queryFoodTypeByFoodTypeId(1);
		List<Food> pizzaList = pizzafoodType.getFoodList();
		
		FoodType snackfoodType = ftb.queryFoodTypeByFoodTypeId(4);
		List<Food> snackList = snackfoodType.getFoodList();
		
		FoodType setmeafoodType = ftb.queryFoodTypeByFoodTypeId(5);
		List<Food> setmeaList = setmeafoodType.getFoodList();
		
		RateBiz rb =new RateBizImpl();
		List<Rate> ratelist = rb.queryAllRate();
		
		NewsBiz  nb = new NewsBizImpl();
		List<News> newslist = nb.queryAllNews();
		
		request.setAttribute("newslist", newslist);
		request.setAttribute("ratelist", ratelist);
		request.setAttribute("foodlist", foodlist);
		request.setAttribute("pizzaList", pizzaList);
		request.setAttribute("setmeaList", setmeaList);
		request.setAttribute("snackList", snackList);
		request.getRequestDispatcher("/index.jsp").forward(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
